<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/admin/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商家管理</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/admin/merchants' }">商家列表</el-breadcrumb-item>
      <el-breadcrumb-item>商家详情</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row class="demo-avatar demo-basic">
        <el-col :span="12">
          <div class="demo-basic--circle">
            <div class="block">
              <el-avatar shape="square" :size="80" :src="imageBaseUrl + this.merchant.restaurant.icon + '.jpg'" class="icon"></el-avatar>
              <span class="nickname">{{merchant.restaurant.rnickname}}</span>
            </div>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <i class="el-icon-location-outline"></i>
          <span>{{merchant.restaurant.address}}</span>
        </el-col>
      </el-row>
      <div class="info-box">
        <el-tabs v-model="activeTab">
          <el-tab-pane label="菜品" name="food">
            <el-table :data="foodList" stripe border>
              <el-table-column type="index" label="序号"></el-table-column>
              <el-table-column label="菜品名" prop="fname"></el-table-column>
              <el-table-column label="菜品详情" prop="detail"></el-table-column>
              <el-table-column label="麻辣" prop="mspicy"></el-table-column>
              <el-table-column label="辣度" prop="spicy"></el-table-column>
              <el-table-column label="鲜度" prop="fresh"></el-table-column>
              <el-table-column label="苦度" prop="bitter"></el-table-column>
              <el-table-column label="咸度" prop="salt"></el-table-column>
              <el-table-column label="酸度" prop="sour"></el-table-column>
              <el-table-column label="甜度" prop="sweet"></el-table-column>
              <el-table-column label="评分" prop="comment" width="150px">
                <template slot-scope="scope">
                  <el-rate v-model="scope.row.comment" disabled text-color="#ff9900">
                  </el-rate>
                </template>
              </el-table-column>
              <el-table-column label="评价数" prop="count"></el-table-column>
            </el-table>
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="queryInfo.pagenum"
              :page-sizes="[5, 10, 15, 20]"
              :page-size="queryInfo.pagesize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total" background>
            </el-pagination>
          </el-tab-pane>
          <el-tab-pane label="其他" name="other">
            <img :src="imageBaseUrl + this.merchant.restaurant.kpicture + '.jpg'" alt="" class="other-image">
            <img :src="imageBaseUrl + this.merchant.restaurant.cpicture + '.jpg'" alt="" class="other-image">
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'MerchantDetails',
  data () {
    return {
      activeTab: 'food',
      merchant: {},
      foodList: [],
      queryInfo: {
        rid: '',
        query: '',
        pagenum: 1,
        pagesize: 5
      },
      total: 0,
      imageBaseUrl: this.$axios.defaults.baseURL + 'static/image/'
    }
  },
  created () {
    this.merchant = this.$route.params.data
    this.getFoodList()
  },
  methods: {
    // 当每页显示的最大数据条数发生变化时，调用该函数
    handleSizeChange (newSize) {
      this.queryInfo.pagesize = newSize
      this.getFoodList()
    },
    // 当当前页数发生变化时，调用该函数
    handleCurrentChange (newPage) {
      this.queryInfo.pagenum = newPage
      this.getFoodList()
    },
    async getFoodList () {
      this.queryInfo.rid = this.merchant.restaurant.rid
      const { data: res } = await this.$axios.get('/admin/restaurant/getFoods', { params: this.queryInfo })
      if (res.status !== 2000) {
        return this.$message.error('获取商家信息失败')
      }
      this.total = res.data.total
      this.foodList = res.data.foods
    }
  }
}
</script>

<style scoped>
.nickname {
  margin-left: 20px;
  font-size: 20px;
}
.info-box {
  margin-top: 20px;
}
.other-image {
  width: 500px;
  height: 300px;
}
</style>
